/**
 * java多线程模式
 * @author andy.rong
 */

package com.myjavalab.thread;

public class SynchonizedTest {

	private static final long CALL_COUNT = 1000000000L;
	public static void main(String[] args) {
		trail("Synch", CALL_COUNT, new Synch());
		trail("NotSynch", CALL_COUNT, new NotSynch());
		
	}
	
	public static void trail(String s, long count, Object o) {
		System.out.println(s + ": Begin");
		long start_time  = System.currentTimeMillis();
		for(int i = 0; i < count; i++) {
			o.toString();
		}
		System.out.println(s + ": End");
		System.out.println("Elapsed time = " + (System.currentTimeMillis() - start_time) + "msec.");
		
	}
}

class NotSynch {
	private static final String name= "NotSynch";
	public String toString() {
		return "[" + name + "]";
	}
}

class Synch {
	private static final String name= "Synch";
	public synchronized String toString() {
		return "[" + name + "]";
	}
}